unit TaskDetailsForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls,
  Task;

type
  TTaskDetailsForm = class(TForm)
    OKButton: TButton;
    CancelButton: TButton;
    TaskNameLabel: TLabel;
    TaskDurationLabel: TLabel;
    TaskNameEdit: TEdit;
    TaskDurationTrackBar: TTrackBar;
    TaskDurationValueLabel: TLabel;
    procedure OKButtonClick(Sender: TObject);
    procedure TaskDurationTrackBarChange(Sender: TObject);
  private
    FTask: TTask;
    procedure SetTask(const Value: TTask);
  public
    class function EditTask(const Task: TTask): Boolean;
    property Task: TTask read FTask write SetTask;
  end;

implementation

uses
  TimeFormat;

{$R *.dfm}

{ TTaskDetailsForm }

procedure TTaskDetailsForm.OKButtonClick(Sender: TObject);
begin
  FTask.Name := TaskNameEdit.Text;
  FTask.Duration := TaskDurationTrackBar.Position;
end;

class function TTaskDetailsForm.EditTask(const Task: TTask): Boolean;
var
  Form: TTaskDetailsForm;
begin
  Form := TTaskDetailsForm.Create(nil);
  try
    Form.Task := Task;
    Result := (Form.ShowModal = mrOk);
  finally
    Form.Free;
  end;
end;

procedure TTaskDetailsForm.SetTask(const Value: TTask);
begin
  FTask := Value;
  TaskNameEdit.Text := Value.Name;
  TaskDurationValueLabel.Caption := TTimeFormat.FormatMinutes(Value.Duration);
  TaskDurationTrackBar.Position := Value.Duration;
end;

procedure TTaskDetailsForm.TaskDurationTrackBarChange(Sender: TObject);
begin
  TaskDurationValueLabel.Caption := TTimeFormat.FormatMinutes(TaskDurationTrackBar.Position);
end;

end.
